package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.*;
import com.itheima.service.OrderService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.ListResourceBundle;
import java.util.Map;

/**
 * @version 1.0
 * @auther gwt
 * @date 2021/6/29 11:32
 */
@RestController
@RequestMapping("/order")
public class OrdersettinglistController {
    @Reference
    private OrderService orderService;


    @RequestMapping("/findPageOrder")
    public PageResult findPageOrder(@RequestBody QueryPageBean queryPageBean) throws Exception {
            return orderService.findPage(queryPageBean);
    }


    @RequestMapping("/add")
    public Result add(@RequestBody OrderManager orderManager){
        try{
            orderService.add(orderManager);
            return new Result(true,"添加成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"添加预约失败");
        }
    }

    @RequestMapping("/edit")
    public Result edit(@RequestBody OrderManager orderManager) {
        try {
            orderService.edit(orderManager);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.EDIT_CHECKITEM_FAIL);
        }
        return new Result(true, MessageConstant.EDIT_CHECKITEM_SUCCESS);
    }

    @RequestMapping("/findOrderById")
    public Result findOrderById(Integer id){
        try {
            Order order = orderService.findOrderById(id);
            return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,order);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL);
        }
    }

    @RequestMapping("/findSetmealIdsByOrderId")
    public Result findSetmealIdsByOrderId(Integer id){
        try {
            List<Integer> setmealIds = orderService.findSetmealIdsByOrderId(id);
            return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,setmealIds);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL);
        }
    }
}
